#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 505;

mt19937 mt(chrono::steady_clock::now().time_since_epoch().count());
int n, k;
int a[N];

int get(int x) {
  int n = sqrt(x * 2);
  if (n * (n + 1) <= x * 2) n++;
  return n;
}
void solve() {
  cin >> k;
  vector<int> ans;
  while (k) {
    int d = get(k);
    k -= d * (d - 1) / 2;
    ans.push_back(d);
  }
  int tot = 0;
  for (int x : ans) tot += x;
  cout << tot << endl;
  int x = 0, y = 0;
  for (int d : ans) {
    rep(i, 1, d) cout << x << ' ' << y + i << endl;
    x++, y += d;
  }
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int t;
  cin >> t;
  while (t--) solve();
  return 0;
}